<template>
  <div>
    <el-menu
        class="el-menu-demo"
        mode="horizontal"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
      <el-menu-item class="user"></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item disabled></el-menu-item>
      <el-menu-item><router-link to="/login">登录</router-link></el-menu-item>
      <el-menu-item><router-link to="/register">注册</router-link></el-menu-item>
    </el-menu>

    <el-card class="box-card">
      <el-form>
        <el-form-item label="账号">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Test1",
  data() {
    return {
      form: {
        name: '111',
        password: '111'
      }
    }
  },
  methods: {
    handleLogin() {
      this.$http.post('/login', this.form).then(res => {
        // 存储session，保存登录状态，将登录的token与用户id存储与session中
        window.sessionStorage.setItem('token', res.data.token)
        window.sessionStorage.setItem('user_id', res.data)
        console.log(res.data.token)
        this.$message('登录成功');
        this.$router.push('/')
      }).catch(err => {
        this.$message('登录失败');
        console.log(err);
      })

    }
  }
}
</script>

<style scoped>
.box-card {
  width: 480px;
  margin: 0 auto;
}
</style>